<html>
<head><meta charset="utf-8"><title>LLVM exceptions · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html">LLVM exceptions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227996522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/227996522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> enterprisey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#227996522">(Feb 26 2021 at 21:24)</a>:</h4>
<p>Is there any writeup of how we use LLVM's exception system in the implementation of panics?</p>



<a name="227998720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/227998720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#227998720">(Feb 26 2021 at 21:40)</a>:</h4>
<p><em>Do</em> we use LLVM's exception system? IIUC, panics are implemented entirely in <code>std</code> and <code>core</code>.</p>



<a name="228002668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/228002668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> enterprisey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#228002668">(Feb 26 2021 at 22:06)</a>:</h4>
<p>Looking at the LLVM IR, we seem to use <code>resume</code> and personality functions; I'm absolutely no expert on the system, but I assume it's used a little</p>



<a name="228005876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/228005876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#228005876">(Feb 26 2021 at 22:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/LLVM.20exceptions/near/227998720">said</a>:</p>
<blockquote>
<p><em>Do</em> we use LLVM's exception system? IIUC, panics are implemented entirely in <code>std</code> and <code>core</code>.</p>
</blockquote>
<p><a href="https://rustc-dev-guide.rust-lang.org/panic-implementation.html#step-2-the-panic-runtime">https://rustc-dev-guide.rust-lang.org/panic-implementation.html#step-2-the-panic-runtime</a> says we use libunwind, I'd assume that's the same as the landing pads from llvm: <a href="https://github.com/rust-lang/rustc-dev-guide/issues/707">https://github.com/rust-lang/rustc-dev-guide/issues/707</a></p>



<a name="228015290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/228015290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#228015290">(Feb 26 2021 at 23:59)</a>:</h4>
<p>LLVM <code>invoke</code> is important too: <a href="https://llvm.org/docs/LangRef.html#invoke-instruction">https://llvm.org/docs/LangRef.html#invoke-instruction</a></p>



<a name="228015444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/228015444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#228015444">(Feb 27 2021 at 00:00)</a>:</h4>
<p>Right, there's a contract between LLVM codegen (invoked via <code>invoke</code> (heh), <code>catchpad</code>, <code>resume</code>, and similar concepts) and the runtime provided by Rust in the form of the personailty function and a way to invoke unwinding</p>



<a name="228015517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/228015517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#228015517">(Feb 27 2021 at 00:01)</a>:</h4>
<p>I'm not sure there's a good writeup, but if there's one for e.g. clang/c++ things described there would be mostly portable to Rust.</p>



<a name="228015606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/LLVM%20exceptions/near/228015606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/LLVM.20exceptions.html#228015606">(Feb 27 2021 at 00:02)</a>:</h4>
<p>Worth noting that how unwinding operates is platform specific, implementation is very different on Windows compared to e.g. Linux.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>